<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="includes/tag.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
    <title>Wcms(内容信息管理系统)</title>
    <script type="text/javascript" src="<%=basePath%>resources/lib/jquery/jquery.js"></script>
    <script type="text/javascript" src="<%=basePath%>resources/lib/webui/buss.ui.core.js"></script>
    <script type="text/javascript" src="<%=basePath%>resources/lib/webui/buss.ui.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/jqgrid/js/i18n/grid.locale-cn.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/jqgrid/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/lib/public.js"></script>
    
    <link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/styles/themes/buss-ui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/jqgrid/css/jquery-ui.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/jqgrid/css/ui.jqgrid.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>resources/styles/public.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>resources/styles/icon.css">
	<link href="<%=basePath%>resources/styles/mainframe.css" media="screen" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
		$(document).ready(function(){		
			$(window).resize(resize);
			resize();
			$(".main_menu a").click(function(){
				$(".main_menu a").css("color","#ffffff");
				$(this).css("color","#eeeeee");
				var url = $(this).attr("url");
				$.post(url,"",function(rs){
					if(rs.message.code != 0){
						$.alert('提示',rs.message.mess,300,140,'warning');
						return;
					}
					getMenuItem(rs.result.data);
				},"json");
			});
			$("#menufirst a").trigger("click");
			$("#current_branch").click(function(){				
				var panel = "<div><div style='margin:5px;'><table id='sel_branch_tabledata'/>" + 
	            "<div id='sel_branch_tablepage'/></div></div>";
				var selDlg = $(panel).dialog({
					modal:true,
					header:true,
					height:395,
					width:600,
					title:"选择店铺信息",
					iconCls:'icon',
					buttons:[
					         {text:'确  定',type:'button',iconCls:'icon-save',handler:function(){
					        	 var selBranchId = $("#sel_branch_tabledata").jqGrid('getGridParam',"selrow");
									if(!selBranchId){
										$.alert('提示','你没有选择店铺信息!',300,140,'info');
										return;
									}			
									selBranchName(selBranchId);
					         }},
					         {text:'取 消',type:'button',iconCls:'icon-cancel',handler:function(){									        	 
					        	 selDlg.dialog("destroy");
					         }}
					        ]
				});
				selectBranchData(selDlg);				
			});
		});
		
		function selBranchName(selBranchId){
			$.post("<%=basePath%>admin/branch/changebrach/"+selBranchId + ".do","",function(rsData){
				 if(rsData.message.code != 0){
					 $.alert("提示","切换当前店铺失败，原因:" + rsData.message.mess,300,140,"error");
					 return;
				 }
				 $("#current_branch").html(rsData.branch.name);
				 location.href = "<%=basePath%>admin/mainframe.do";
			 },"json");
		}
		
		
		function selectBranchData(selDlg){
    		var url = "<%=basePath%>admin/branch/listbranchbyroles.do?status=normal";
    		var colNames = ["店铺名称","联系人","联系电话","当前状态"];
    		var colModel = [
    		                {name:'name',index:'name',width:150,align:'left',formatter:function(cellValue,opts,rowObj){
    		                	return "<a style='text-decoration: underline;' href='javascript:selBranchName("+rowObj.id+")'>"+cellValue+"</a>";
    		                }},
    		                {name:'contact',index:'contact',width:100,align:'left'},
    		                {name:'contactNumber',index:'contactNumber',width:100,align:'left'},
    		                {name:'status',index:'status',width:60,align:'center',formatter:syscore.formaterStatus}
    		               ];
    		selDlg.find("#sel_branch_tabledata").jqGrid({
    			url:url,
    			mtype:'post',
    			datatype:'json',
    			height:305,
    			multiboxonly:true,
    			autowidth:true,
    			autoencode:true,
    			viewrecords:true,
    			forceFit:true,
    			gridview:true,
    			loadui:'block',
    			rowNum:0,
    			sortorder:'asc',
    			rownumbers:true,
    			colNames:colNames,
    			colModel:colModel,
    			jsonReader:{
    				id:'id',
    				root:'result.data',
    				page:'result.page.curPageNo',
    				total:'result.page.totalPage',
    				repeatitems:false
    			},
    			prmNames:{
    				page:'page.curPageNo',
    				rows:'page.pageSize',
    				sort:'orderField',
    				order:'orderType'		
    			},
    			page:1,
    			pagerpos:'left',
    			pager:selDlg.find("#sel_branch_tablepage")
    		});    		
    	};
		
		/**设置子菜单项*/
		function getMenuItem(menuItems){
			var menuLi = "";
			for(var i = 0;i < menuItems.length;i++){
				var url = menuItems[i].menuUrl != null ? menuItems[i].menuUrl : 'javascript:void(0);';
				var name = menuItems[i].name;
				menuLi += "<li>";
				menuLi += "<div class='nav_item_title'>";
				menuLi += "<a class='nav_item_a' href='"+url+"'>"+name+"</a>";
				menuLi += "</div>";
				if(i == 0){
					menuLi += "<ul hide='false'>";
				}else{
					menuLi += "<ul style='display: none;' hide='true'>";
				}				
				var childMenuLi = "";
				for(var j = 0;j < menuItems[i].nodes.length;j++){
					var childUrl = menuItems[i].nodes[j].menuUrl != null ? menuItems[i].nodes[j].menuUrl : 'javascript:void(0);';
					var childName = menuItems[i].nodes[j].name;
					menuLi += "<li><a href='<%=basePath%>"+genMenuId(childUrl,menuItems[i].nodes[j].id)+"' target='functionframe'>"+childName+"</a></li>";
				}
				menuLi += "</ul>";
				menuLi += "</li>";				
			}
			$(".nav_menu_item").html(menuLi);
			if($.browser.msie){
				$(".nav_item_title").css("padding-top","7px");
			}
			$(".nav_menu_item").find(".nav_item_a").click(function(){				
				var isHide = $.trim($(this).parent().parent().children("ul").attr("hide"));
				isHide = isHide == "" || isHide == "false" ? "false" : "true";
				if(isHide == "false"){
					$(this).parent().parent().children("ul").attr("hide","true");
					$(this).parent().parent().children("ul").hide();
				}else{
					$(this).parent().parent().children("ul").attr("hide","false");
					$(this).parent().parent().children("ul").show();
				}
			});
		}
		
		function genMenuId(url,menuId){
			if(url.indexOf("?") == -1){
				url += "?menuid=" +  menuId;
			}else{
				url += "&menuid=" + menuId;
			}
			return url;
		}
		
		function resize(){	
			var wh = $(window).height();
			$(".container").height(wh);
			var frameTopH =  $(".frameTop").height();
			var footerH = $(".frame_footer").height();
			var h = wh - frameTopH - footerH;
			
			$(".framecontainer").height(h);
			
			$(".frameleft").height(h);
			$(".nav_menu_item").height(h - $(".nav_item_title").outerHeight());
		} 
	</script>
	<style type="text/css">
		
	</style>
  </head>
  <body>
  	<div class="container" >
  		<div class="frameTop" style="height:74px;width: 100%;">
	    	<table cellpadding="0" cellspacing="0" width="100%" height="100%">
	    		<tr>
	    			<td style="width:9px;" class="top_leftTd"></td>
	    			<td valign="top">
	    				<table cellpadding="0" cellspacing="0" width="100%" height="45">
	    					<tr>
	    						<td width="280" class="main_logo"></td>
	    						<td align="left" valign="bottom" style="word-break : keep-all; overflow: hidden;">
	    							<ul class="main_menu">
	    								<c:forEach items="${menus}" var="menu" varStatus="st">
	    									<c:if test="${st.first}">
	    										<li id='menufirst'><a href="javascript:void(0);" url="<%=basePath%>admin/sysmenu/listByRole/${menu.id}.do">${menu.name}</a> </li>
	    									</c:if>
	    									<c:if test="${st.last && !st.first}">
	    										<li id="menulast"><a href="javascript:void(0);" url="<%=basePath%>admin/sysmenu/listByRole/${menu.id}.do">${menu.name}</a> </li>
	    									</c:if>
	    									<c:if test="${st.last && st.first}">
	    										<li id="menulast"></li>
	    									</c:if>
	    									<c:if test="${!st.first && !st.last}">
	    										<li><a href="javascript:void(0);" url="<%=basePath%>admin/sysmenu/listByRole/${menu.id}.do">${menu.name}</a> </li>
	    									</c:if>
	    								</c:forEach>
		    						</ul>
	    						</td>
	    						<td width="27">
	    							<div class="logout"><a href="<%=basePath%>admin/logout.do" style="display:block;height:100%;width:100%;"/></div>
	    						</td>
	    					</tr>
	    				</table>
	    				<div style="width:100%;">
		    				<ul class="other_nav">		   				
		    					<li><div><span class="nav_currentBranch">当前店铺：</span><a href="#" id="current_branch" style="float:left;padding-left: 0;color:#194964;text-decoration: underline;">${branchName }</a></div></li>
		    					<li><a href="#" class="nav_ggxx">公告信息</a> </li>
		    					<li><a href="#" class="nav_wdrc">我的日程</a> </li>
		    					<li><a href="#" class="nav_wdtxl">我的通信录</a> </li>
		    					<li><a href="#" class="nav_dqzx">当前在线</a> </li>
		    				</ul>
		    				<div  class="nav_timer">日期:2011年04月07日 星期四</div>
	    				</div>
	    			</td>
	    			<td width="9" class="top_rightTd"></td>
	    		</tr>
	    	</table>
	    </div>
	    <div class="framecontainer">
	  		<div class="frameleft">  			
	  			<div class="menu_container">
	  				<div class="nav_menu_title" >
		  				<span class="nav_menu">菜单导航</span>
		  			</div>
		  			<ul class="nav_menu_item">
		  				
		  			</ul>
	  			</div>
	  		</div>
	  		 <div class="framemain"> 
				<iframe width="100%" frameborder="0"  height="100%" name="functionframe"
					src="<%=basePath%>admin/modelpage.do"></iframe>
			</div> 
		</div>
  		<div class="frame_footer" >
  			<table cellpadding="0" cellspacing="0" width="100%" height="100%">
  				<tr>
  					<td class="main_footer_left"></td>
  					<td class="main_footer_center">&nbsp; </td>
  					<td class="main_footer_right"></td>
  				</tr>
  			</table>
  		</div>
  	</div>
  </body>
</html>